package com.novabluetooth.services;

import java.util.Arrays;

import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;

import com.health.viewscontrols.medical.base.DeviceEnum;
import com.novabluetooth.services.servicedevices.TiZhongFatScaleService;
import com.novabluetooth.views.twj.TwjConstans;

/**
 * 蓝牙相关工具类
 *
 * @author nova
 */
public class BluetoothConstant {

    public final static String REGISTER_GB = "com.example.communication.RECEIVER2";
    public final static String REGISTER_EW = "com.example.communication.REGISTER_EW";
    public final static String REGISTER_Waiting = "com.example.communication.REGISTER_Waiting";
    // 华清心电----------
    public final static String ECG_PATH_XML = "/ECGDATA/XML/";
    public final static String ECG_PATH_JPEG = "/ECGDATA/JPEG/";
    public final static String TIWEN_HTD2 = "NOVAEW";
    /**
     * 心电
     */
    public final static String ECG = "ECG";
    public final static String ECG_TYPENAME = "心电";
    /**
     * 体重
     */
    public final static String TIZHONG = "TIZHONG";
    public final static String TIZHONG_TYPENAME = "体重";
//    public final static String TIZHONG_TYPENAME2 = "轻体重";
    public final static String TIZHONG_TYPENAME2 = "体重";
    public final static String TIZHONG_TYPENAME3 = "体脂";
    /**
     * 轻加
     */
    public final static String TIZHONGQing = "TIZHONGQing";
//    public final static String TIZHONG_TYPENAME = "体重";
public final static String TIZHONGQing2 = "newTIZHONGQing";
    /**
     * 血氧
     */
    public final static String XUEYANG = "XUEYANG";
    public final static String XUEYANG_TYPENAME = "血氧";
    /**
     * 血糖
     */
    public final static String XUETANG = "XUETANG";
    public final static String XUETANG_TYPENAME = "血糖";

    /***
     * 脉搏波3.0版本
     */
    public final static String MAIBOBO = "MAIBOBO";
    public final static String MAIBOBO_TYPENAME = "脉搏波";

    /***
     * 脉搏波4.0版本
     */
    public final static String MAIBOBO4 = "MAIBOBO4";
    public final static String MAIBOBO_TYPENAME4 = "脉搏波";
    /**
     * 血脂仪
     */
    public final static String XUEZHI = "XUEZHI";
    public final static String XUEZHI_TYPENAME = "血脂";
    /**
     * 血压
     */
    public final static String XUEYA = "XUEYA";
    public final static String XUEYA_TYPENAME = "血压";
    /**
     * 体温
     */
    public final static String TIWEN = "TIWEN";
    public final static String TIWEN_TYPENAME = "体温";

    public final static String EWENQIANG = "EWENQIANG";
    public final static String EWENQIANG_TYPENAME = "额温枪";
    /**
     * 尿常规
     */
    public final static String NIAOCHANGGUI = "BLE-EMP-Ui";
//    public final static String NIAOCHANGGUI = "NIAOCHANGGUI";
    public final static String NIAOCHANGGUI_UI = "BLE-EMP-Ui";
    public final static String NIAOCHANGGUI_TYPENAME = "恩普生";
//    public final static String NIAOCHANGGUI_TYPENAME = "尿常规";

    /**
     * 血红蛋白
     */
    public final static String HB = "XUETANG";
    public final static String HB_TYPENAME = "血红蛋白";


    /**
     * 耳温
     */
    public final static String TIWEN_EWQ_NOVA = "NOVATF_LE";
    public final static String TIWEN_EWQ_HTD = "HTD02";// HTD02和泰达耳温枪，HC-08和泰达额温枪
    public final static String TIWEN_EWENQ_HTD = "HC-08";
    public final static String TIWEN_EWENQ_HTD2 = "NOVAEW";
    public final static  String TIWEN_EWENQ_HTD3="SH-HC-08";

    /**
     * 血糖
     */
    //三诺(安稳型)血糖仪
    public final static String XUETANG_AMX_SANNUO = "NOVABG_LE";
    //三诺（WL-1型）血糖仪
    public final static String XUETANG_WL_1_SANNUO = "Sinocare";

    // 鱼跃760血糖仪(怡成血糖仪通信协议相同)
    public final static String XUETANG_YUYUE760_YUYUE = "Yuwell Glucose";


    /**
     * 血氧
     */
    //贝瑞血氧
    public final static String XUEYANG_BM = "BerryMed";
    //黑色诺安血氧
    public final static String XUEYANG_NOVA = "NOVABT_LE";
    //科瑞康(力康)血氧
    public final static String XUEYANG_LIKANG_KRK = "POD";
    //科瑞康(力康)血氧 新设备名称
//    public final static String XUEYANG_LIKANG_KRK_PC = "PC-60F_SN007836";
    public final static String XUEYANG_LIKANG_KRK_PC = "PC-60F";
    public final static String XUEYANG_LIKANG_KRK_PC_NAME = "科瑞康血氧";
    /**
     * 血脂仪CardioChek Meter
     */
    public final static String XUEZHI_CARDIOCHEK = "CardioChek Meter";//蓝牙name

    /**
     * 体重
     */
    //诺安体重
    public final static String TIZHONG_NOVA = "NOVABW_LE";
    //脂肪秤
    public final static String TIZHONG_FATSCALE = "000FatScale01";
    //轻加脂肪秤
    public final static String TIZHONG_HEALTH = "Health Scale";
    public final static String TIZHONG_HEALTH1 = "HeartRate Scale";
    /**
     * 血压计
     */
    //康泰O8A血压计
    public static final String XUEYA_CONTEC08A_KTXYJ = "NIBP010095";
    public static final String XUEYA_CONTEC08A1_KTXYJ = "NIBP031217";
    public final static String XUEYA_KANGTAI = "CONTEC BloodPressure";

    //捷美瑞血压计
    public final static String XUEYA_JMR = "BPM-188";
    public final static String XUEYA_JMR2 = "H.HOME BP";

    // 鱼跃血压计（YE680A）
    public final static String XUEYA_YE680A_YUYUE = "Yuwell BloodPressure";
    //鱼跃血压计（Yuwell BP-YE680A）
    public final static String XUEYA_YE680A_YUYUE2 = "Yuwell BP-YE680A";
    // 优瑞恩血压计
    public final static String XUEYA_YOURIEN = "Bluetooth BP";
    /**
     * 血红蛋白
     */
    //血红蛋白--易捷
    public final static String XUEHONGDANBAI_NOVA = "NOVAHB1_LE";

    public final static String BEITAITIZHONG = "Body Fat-B1";

    public final static String BEITAIEWENQIANG = "Belter_TP";

    /**
     * 尿液分析仪
     */
    //汉唐尿液分析仪HT-111A
    public final static String NIAOJI_HT111A_HANTANG = "NOVAUR_LE";
    //康泰尿机
    public final static String NIAOJI_KANGTAINIAOJI = "BC014062";
    public final static String NIAOJI_KANGTAINIAOJI2 = "BC014244";

    /**
     * 百捷三合一
     */

    public final static String BENECHECK_TRIPLE = "BeneCheck TC-B DONGLE";

    public final static String BeneCheck = "BeneCheck";
    /**
     * 百捷三合一
     */
    public final static String TRIPLE = "TRIPLE";
    public final static String TRIPLE_TYPENAME = "百捷三合一";
    /**
     * 百捷血红蛋白分析仪
     */
    public final static String TRIPLE_TYPENAME_HB = "百捷血红蛋白分析仪";

    /**
     * 百捷三合一（血糖）
     */
    public final static String TRIPLE_DATA_GLUC = "41";
    /**
     * 百捷三合一（尿酸）
     */
    public final static String TRIPLE_DATA_UA = "51";
    /**
     * 百捷三合一（胆固醇）
     */
    public final static String TRIPLE_DATA_CHOL = "61";

    /**
     * 百捷三合一（血红蛋白）
     */
    public final static String TRIPLE_DATA_HB = "E1";

    /**
     * 胆固醇
     *
     */
    public final static String DGC_TYPENAME = "胆固醇";

    /**
     * 家康红外体温计
     *
     */
    public final static String TW_JK = "JKFR";

    /** e家医护 */
    public final static String PW_01DEVICE_NAME = "PW-01";
    public static String PW_01DEVICE_NAME_TYPENAME = "e家医护";




    public static final String CMS50EW = "CMS50EW";
    public static final String CMS50EW1 = "SpO201";

    public static final Object DEVICE_NAME1 = XUEYA_CONTEC08A_KTXYJ;
    public static final Object DEVICE_NAME2 = XUEYA_CONTEC08A1_KTXYJ;

    public final static String WAIST = "GR-94103";
    public final static String WAIST1 = "Health-tape";
    public final static String WAIST_NAME = "腰臀比";

    /**
     * 获取设备测量类型
     */
    public static String getCLTypeName(String queryIndex) {
        if (TextUtils.isEmpty(queryIndex)) {
            return "";
        }
        String typename = "";
        switch (queryIndex) {
            case BluetoothConstant.PW_01DEVICE_NAME:
                typename = BluetoothConstant.PW_01DEVICE_NAME;
                break;
            case TwjConstans.DEVICE_NAME:
                typename = BluetoothConstant.TIWEN_TYPENAME;
                break;
            case BluetoothConstant.TIZHONG:
                typename = BluetoothConstant.TIZHONG_TYPENAME;
                break;
            case BluetoothConstant.TIZHONGQing:
                typename = BluetoothConstant.TIZHONG_TYPENAME;
                break;
            case BluetoothConstant.TIWEN:
                typename = BluetoothConstant.TIWEN_TYPENAME;
                break;
            case BluetoothConstant.XUEYANG:
                typename = BluetoothConstant.XUEYANG_TYPENAME;
                break;
            case BluetoothConstant.XUEYA:
                typename = BluetoothConstant.XUEYA_TYPENAME;
                break;
            case BluetoothConstant.XUETANG:
                typename = BluetoothConstant.XUETANG_TYPENAME;
                break;
            case BluetoothConstant.NIAOCHANGGUI:
                typename = BluetoothConstant.NIAOCHANGGUI_TYPENAME;
                break;
            case BluetoothConstant.ECG:
                typename = BluetoothConstant.ECG_TYPENAME;
                break;
            case BluetoothConstant.TRIPLE:
                typename = BluetoothConstant.TRIPLE_TYPENAME;
                break;
            case BluetoothConstant.XUEZHI:
                typename = BluetoothConstant.XUEZHI_TYPENAME;
                break;
            case BluetoothConstant.EWENQIANG:
                typename = BluetoothConstant.EWENQIANG_TYPENAME;
                break;
            case BluetoothConstant.TIZHONGQing2:
//                typename = BluetoothConstant.TIZHONG_TYPENAME2;
                typename = BluetoothConstant.TIZHONG_TYPENAME3;
                break;
            case BluetoothConstant.MAIBOBO:
                typename = BluetoothConstant.XUEYA_TYPENAME;
                break;
            case BluetoothConstant.BeneCheck:
                typename = BluetoothConstant.TRIPLE_TYPENAME;
                break;
            case BluetoothConstant.MAIBOBO4:
                typename = BluetoothConstant.XUEYA_TYPENAME;
                break;
            case "BeneCheck TC-B DONGLE":
                typename = "血红蛋白";
                break;
            case "LYSUN BHM-101":
                typename = "血红蛋白";
                break;
            case "WAIST":
                typename = "腰臀比";
                break;
            case "FM2":
                typename = "FM2";
                break;
            case "RTCF_DH":
                typename = "RTCF_DH";
                break;
            case "PEF_SP":
                typename = "PEF_SP";
                break;
        }
        return typename;
    }

    /**
     * 获取设备名
     *
     * @param name
     * @return
     * @author 王婷婷
     * @date 2017年7月13日 下午3:43:39
     */
    public static String getNovaDevice(String name) {
        String[] novaDevices = {BluetoothConstant.TIWEN_EWQ_NOVA, BluetoothConstant.TIWEN_EWENQ_HTD,
                BluetoothConstant.TIWEN_EWQ_HTD, BluetoothConstant.TIZHONG_NOVA,

                BluetoothConstant.XUETANG_AMX_SANNUO, BluetoothConstant.XUETANG_WL_1_SANNUO,
                BluetoothConstant.XUETANG_YUYUE760_YUYUE,

                BluetoothConstant.XUEYANG_NOVA, BluetoothConstant.XUEYANG_BM, BluetoothConstant.XUEYANG_LIKANG_KRK,

                BluetoothConstant.XUEYA_JMR, BluetoothConstant.XUEYA_JMR2, BluetoothConstant.XUEYA_KANGTAI,
                BluetoothConstant.XUEYA_YOURIEN, BluetoothConstant.XUEYA_YE680A_YUYUE,

                BluetoothConstant.NIAOJI_HT111A_HANTANG, BluetoothConstant.NIAOJI_KANGTAINIAOJI,
                BluetoothConstant.NIAOJI_KANGTAINIAOJI2,

                BluetoothConstant.XUEHONGDANBAI_NOVA,BluetoothConstant.TW_JK,
                BluetoothConstant.XUEYA_YE680A_YUYUE2,BluetoothConstant.TIWEN_EWENQ_HTD3,
                BluetoothConstant.BEITAITIZHONG,BluetoothConstant.BEITAIEWENQIANG,
                BluetoothConstant.NIAOCHANGGUI_UI,BluetoothConstant.PW_01DEVICE_NAME,
                BluetoothConstant.BENECHECK_TRIPLE,
        TwjConstans.DEVICE_NAME, BluetoothConstant.WAIST};
        int indexOf = Arrays.asList(novaDevices).indexOf(name);
        String novaName = "";

        System.out.println("搜索到=========="+name);
        if (name.startsWith("PULMO80B") || name.startsWith("PULMO70B")
                || name.startsWith("PULMO80BEXP") || name.startsWith("PULMO70BEXP")
                || name.startsWith("PULMO01")|| name.startsWith("PULMO70A")
                || name.startsWith("PULMO80A") || name.startsWith("PULMO80BFC1")) {
            return "肺功能";
        }

        if(!TextUtils.isEmpty(name) && name.length() > 6) {
            if(name.startsWith("FSRKB_BT-001")){
                return "辰浩血压计";
            }
        }

        if(!TextUtils.isEmpty(name) && name.length() > 6) {
            if(name.startsWith("FSRKB_BT")){
                return "辰浩体温计";
            }
        }

        if(!TextUtils.isEmpty(name) && name.length() > 6) {
            if(name.startsWith("SN-4Y")){
                return "三诺臻准2000血糖";
            }
        }

        if(!TextUtils.isEmpty(name) && name.length() > 10) {
            if(name.startsWith("HS")){
                return "e家医护三合一";
            }
        }

        if(name.length() > 8) {
            if(name.startsWith("DHBF")) {
                return "DH人体成分";
            }
        }

        if(name.length() > 8) {
            if(name.startsWith("DH")&&!name.startsWith("DHBF")) {
                return "DH身高体重秤";
            }
        }

        if(name.length() > 6) {
            if(BluetoothConstant.WAIST.equals(name)) {
                novaName = BluetoothConstant.WAIST_NAME;
                return novaName;
            }
        }
        if(name.length() > 6) {
            if(name.contains(WAIST1)) {
                novaName = BluetoothConstant.WAIST_NAME;
                return novaName;
            }
        }

        if("BerryMed".equals(name)){
            novaName = "贝瑞血氧";
            return novaName;
        }

        if("BLE_VivaChek".equals(name)||"BLE_Glucowell".equals(name)){
            novaName = "微策三合一";
            return novaName;
        }
        if(name.equals(BluetoothConstant.NIAOCHANGGUI_UI)){
            novaName = "尿常规";
            return novaName;
        }

        if(name.length() > 8) {
            if(name.equals("Yuwell BP-YE660D")){
                return "鱼跃血压计";
            }
        }
        if(name.length() > 8) {
            if(name.equals("Yuwell HT-YHW")){
                return "鱼跃体温计";
            }
        }
        if(name.length() > 8) {
            if(name.startsWith("Yuwell BO")){
                return "鱼跃血氧";
            }
        }
        if(name.length() > 8) {
            if(name.startsWith("Yuwell Glucose")){
                return "鱼跃血糖";
            }
        }
        // LYSUN BHM-101 e家血红蛋白
        if(name.length() > 8) {
            if(name.startsWith("LYSUN")){
                return "e家血红蛋白";
            }
        }

        if(name.length() > 6) {
            if(name.contains(TwjConstans.Bioland_BG)){
                // 数据库查询也使用这个名字
                return TwjConstans.Bioland_BG_NAME;
            }
        }

        if(name.length() > 6) {
            if(name.contains(TwjConstans.Bioland_BP)){
                // 数据库查询也使用这个名字
                return TwjConstans.Bioland_BP_NAME;
            }
        }

        if(name.length() > 10) {
            if(name.startsWith("ST710-")) {
                return "ST710读卡器";
            }
        }

        if(name.length() > 6) {
            if("ChoiceMMed_C208S".equals(name)){
                return "血氧CHS";
            }
        }

        if(name.length() > 6){
            if(name.contains(TwjConstans.DEVICE_NAME)){
                novaName = TwjConstans.DEVICE_NAME_TYPENAME;
                return novaName;
            }
        }

        if(name.length() > 9){
            if(name.equals("BeneCheck TC-B DONGLE")){
                novaName = "百捷血红蛋白";
                return novaName;
            }
        }


        if(name.length() > 9){
            String subName = name.substring(0, 9);
            if(subName.equals("BeneCheck")){
                novaName = "百捷设备";
                return novaName;
            }
        }
        if(name.length() > 5){
            String subName = name.substring(0, 5);
            Log.e("TAG","获取前九位："+subName);
            if(subName.contains("Body")){
                novaName = "倍泰体脂秤";
                return novaName;
            }
        }
        if(name.length() > 2){
            String subName = name.substring(0, 3);
            Log.e("TAG","获取前九位："+subName);
            if(subName.contains("BP")){
//                novaName = "脉搏波血压计";
                novaName = DeviceEnum.BP.getTitle();
                return novaName;
            }
        }
        if(name.length() > 5){
            Log.e("TAG","获取前九位："+name);
            if(name.contains(BluetoothConstant.XUEYANG_LIKANG_KRK_PC)){
                novaName = XUEYANG_LIKANG_KRK_PC_NAME;
                return novaName;
            }
        }

        if(name.length() > 4){
            Log.e("TAG","获取前九位："+name);
            if(name.contains(BluetoothConstant.PW_01DEVICE_NAME)){
                novaName = PW_01DEVICE_NAME_TYPENAME;
                return novaName;
            }
        }
        switch (indexOf) {

            case -1:
                if (name.contains("NIBP03") || name.equals(BluetoothConstant.DEVICE_NAME2)) {
                    novaName = "康泰血压计08A-BT";
                    break;
                }
                if (name.startsWith("SS-")) {
                    novaName = "神思身份证读卡器";
                    break;
                }
                if (name.startsWith("KT8000_")) {
                    novaName = "卡尔身份证读卡器";
                    break;
                }
                if (name.equals(BluetoothConstant.BENECHECK_TRIPLE)) {
                    novaName = "百捷血红蛋白";
                    break;
                }
                if (name.equals(BluetoothConstant.TIZHONG_FATSCALE)) {
                    novaName = "脂肪秤";
                    break;
                }
                if (name.equals(BluetoothConstant.TIZHONG_HEALTH)||name.equals(BluetoothConstant.TIZHONG_HEALTH1)) {
                    novaName = "轻加脂肪秤";
                    break;
                }
                if (name.equals(BluetoothConstant.XUEZHI_CARDIOCHEK)) {
                    novaName = "卡迪克血脂仪";
                    break;
                }
                break;
            case 0:
                novaName = "诺安耳温枪";
                break;
            case 1:
                novaName = "和泰达额温枪";
                break;
            case 2:
                novaName = "和泰达耳温枪";
                break;
            case 3:
                novaName = "诺安体重";
                break;
            case 4:
                novaName = "三诺安稳型血糖仪";
                break;
            case 5:
                novaName = "三诺WL-1型血糖仪";
                break;
            case 6:
                novaName = "鱼跃760血糖仪";
                break;
            case 7:
                novaName = "诺安血氧";
                break;
            case 8:
                novaName = "贝瑞血氧";
                break;
            case 9:
                novaName = "科瑞康血氧";
                break;
            case 10:
                novaName = "捷美瑞血压计";
                break;
            case 11:
                novaName = "捷美瑞血压计";
                break;
            case 12:
                novaName = "康泰08A血压计";
                break;
            case 13:
                novaName = "优瑞恩血压计";
                break;
            case 14:
                novaName = "鱼跃血压计YE680A";
                break;
            case 15:
                novaName = "诺安尿液分析仪";
                break;
            case 16:
                novaName = "康泰尿液分析仪BC401BT";
                break;
            case 17:
                novaName = "康泰尿液分析仪BC401BT";
                break;
            case 18:
                novaName = "诺安血红蛋白分析仪";
                break;
            case 19:
                novaName = "家康红外体温计";
                break;
            case 20:
                novaName = "鱼跃血压计";
                break;
            case 21:
                novaName = "和泰达额温枪";
                break;
            case 22:
                novaName = "倍泰体脂秤";
                break;
            case 23:
                novaName = "倍泰额温枪";
                break;
            default:
                novaName = "";
                break;
        }
        return novaName;
    }

}
